<%@ page isErrorPage="false" language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255" 
    import="java.util.List, 
    com.optimus.dao.ProductDAO, 
    com.optimus.model.mapped.ProductBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<link rel="stylesheet" type="text/css" href="../style-projects-jquery.css" />   
    
    <script type="text/javascript" src="js/LightBoxJS/jquery.js"></script>
    <script type="text/javascript" src="js/LightBoxJS/jquery.lightbox-0.5.js"></script>
    <link rel="stylesheet" type="text/css" href="css/LightBoxCSS/jquery.lightbox-0.5.css" media="screen" />
    
    <script type="text/javascript">
    $(function() {
        $('#gallery a').lightBox();
    });
    </script>
   	<style type="text/css">
	/* jQuery lightBox - Gallery style */
	#gallery {
		background-color: #1d1d1d;
		padding: 10px;
		width: 520px;
		left: 175px;
		top: 100px;
	}
	#gallery ul { list-style: none; }
	#gallery ul li { display: block; }
	#gallery input {
		border: 5px solid #1d1d1d;
		border-width: 5px 5px 20px;
	}
	#gallery form:hover input {
		border: 5px solid #3e3e3e;
		border-width: 5px 5px 20px;
		color: #fff;
	}
	#gallery form:hover { color: #fff; }
	</style>
</head>

<body>
<%@ include file="loginHeader.jsp"%>
<%@ include file="searchBar.jsp"%>
<%@ include file="leftSideNavMenu.jsp"%>
<%@ include file="shoppingCartBean.jsp"%>
<%
	int categoryId = 1;
	if (request.getParameter("cid") != null)
	{
		categoryId = Integer.valueOf(request.getParameter("cid"));
	}
	int squareSize = 128;
	ProductDAO productDAO = (ProductDAO) SpringUtils.getBean("productDAO");
	List<ProductBean> productsList = null;
	if (request.getParameter("search") != null)
	{
		productsList = productDAO.selectAllProductsBySearch(categoryId, request.getParameter("search"));
	}
	else
	{
		productsList = productDAO.selectAllProductsByCategory(categoryId, null);
	}
%>
<div id="gallery" style="position: absolute;">
	<table>
	<%
		int i=0;
		out.print("<tr>");
		if ((productsList == null) || (productsList.isEmpty()))
		{
			out.print("<h3><center>No results were found !</center></h3>");
		}
		else
		{
			for (ProductBean product : productsList)
			{
				i++;
				out.print("<td>");
				out.print("<form action=\"productPage.jsp\" method=\"post\">");
				out.print("<input type=\"hidden\" name=\"id\" value=\""+product.getId()+"\"");
				out.print("<input type=\"hidden\" name=\"name\" value=\""+product.getName()+"\"");
				out.print("<input type=\"hidden\" name=\"picturePath\" value=\""+product.getPicturePath()+"\"");
				out.print("<input type=\"hidden\" name=\"price\" value=\""+product.getPrice()+"\"");
				out.print("<input type=\"hidden\" name=\"categoryId\" value=\""+product.getCategoryId()+"\"");
				out.print("<input type=\"hidden\" name=\"description\" value=\""+product.getDescription()+"\"");
				out.print("<input type=\"image\" src=\""+product.getPicturePath()+"\" width=\""+squareSize+"\" height=\""+squareSize+"\" value=\""+product.getName()+"\"/>");
				out.print("</form>");
				out.print("</td>");
				if (i % 3 == 0)
				{
					out.print("</tr><tr>");
				}		
			}
			out.print("</tr>");
		}
	%>
	</table>
</div>

<%@ include file="footer.jsp"%>
</body>
</html>